package com.example.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.model.jdao.ExcelUtils;
import com.example.pojo.ExcelData;

@RestController
@RequestMapping("/excel")
public class ExcelController {
     @RequestMapping(value = "/export")
        public void excel(HttpServletResponse response,ExcelInfo excelInfo) throws Exception {
            ExcelData data = new ExcelData();
            data.setName("用户信息数据");
            //添加表头
            excelInfo.setNames(new String[] {"多少行1","多少行2","多少行3","多少行4"});
            excelInfo.setAccount("测试excelInfo");
            excelInfo.setDept("测试Dept");
            
            List<String> titles = new ArrayList();
            //for(String title: excelInfo.getNames())
            titles.add("第一个");
            titles.add("第2个");
            titles.add("第3个");
            titles.add("第4个");
            data.setTitles(titles);
            //添加列
            List<List<Object>> rows = new ArrayList();
            List<Object> row = null;
           for(int i=1; i<excelInfo.getNames().length;i++){
               row=new ArrayList();
               row.add(1);
               row.add(2);
               row.add(3);
               row.add("rrr");
               rows.add(row);

           }

         data.setRows(rows);

            String fileName="小鹏"+".xls";
            ExcelUtils.exportExcel(response, fileName, data);
        }
}